package com.yhq.oj.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yhq.oj.common.BaseResponse;
import com.yhq.oj.common.ErrorCode;
import com.yhq.oj.common.ResultUtils;
import com.yhq.oj.exception.BusinessException;
import com.yhq.oj.judge.JudgeService;
import com.yhq.oj.model.dto.questionsubmit.QuestionSubmitQueryRequest;
import com.yhq.oj.model.entity.QuestionSubmit;
import com.yhq.oj.model.entity.User;
import com.yhq.oj.model.vo.QuestionSubmitVO;
import com.yhq.oj.service.QuestionSubmitService;
import com.yhq.oj.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.concurrent.CompletableFuture;

/**
 * 题目提交接口
 *
 * @author yhq
 */
@RestController
//@RequestMapping("/question_submit")
@Slf4j
@Deprecated
public class QuestionSubmitController {

    @Resource
    private QuestionSubmitService questionSubmitService;

    @Resource
    private UserService userService;
    @Resource
    @Lazy
    private JudgeService judgeService;

    /**
     * 做题页面提交代码
     *
     * @param questionSubmitRequest
     * @param request
     * @return resultNum 本次点赞变化数
     */
//    @PostMapping("/")
//    public BaseResponse<Long> IntegerionSubmit(@RequestBody com.yhq.oj.model.dto.questionsubmit.QuestionSubmitRequest questionSubmitRequest,
//                                               HttpServletRequest request) {
//        if (questionSubmitRequest == null || questionSubmitRequest.getQuestionId() <= 0) {
//            throw new BusinessException(ErrorCode.PARAMS_ERROR);
//        }
//        // 登录才能做题
//        final User loginUser = userService.getLoginUser(request);
//        long questionSubmitId = questionSubmitService.questionSubmit(questionSubmitRequest, loginUser);
////        异步执行
//        CompletableFuture.runAsync(() -> {
//            judgeService.doJudge(questionSubmitId);
//        });
//        return ResultUtils.success(questionSubmitId);
//    }
//
//    /**
//     * 分页获取题目提交情况列表（仅管理员）
//     *
//     * @param questionSubmitQueryRequest
//     * @param request
//     * @return
//     */
//    @PostMapping("/list/page")
//    public BaseResponse<Page<QuestionSubmitVO>> listQuestionSubmitByPage(@RequestBody QuestionSubmitQueryRequest questionSubmitQueryRequest,
//                                                                         HttpServletRequest request) {
//        long current = questionSubmitQueryRequest.getCurrent();
//        long size = questionSubmitQueryRequest.getPageSize();
////        从数据库中得到原始的数据
//        Page<QuestionSubmit> questionSubmitPage = questionSubmitService.page(new Page<>(current, size),
//                questionSubmitService.getQueryWrapper(questionSubmitQueryRequest));
////        脱敏
//        User loginUser = userService.getLoginUser(request);
//        Page<QuestionSubmitVO> questionSubmitVOPage = questionSubmitService.getQuestionSubmitVOPage(questionSubmitPage, loginUser);
//
//        return ResultUtils.success(questionSubmitVOPage);
//    }
//
}
